const { validationResult } = require("express-validator");
const { Send } = require("../utils/response");
const banner = require("./banner");
const notice = require("./notice");
const user = require("./user");
const category = require("./category");
const gallery = require("./gallery");
const collection = require("./collection");
const wallpaper = require("./wallpaper");

const Validator = (rules) => {
    return [
        ...rules,
        (req, res, next) => {
            const errors = validationResult(req);
            if (!errors.isEmpty()) {
                return Send(res, {
                    code: -1,
                    message: errors.array().map((error) => error.msg)[0]
                });
            }
            next();
        }
    ];
};

module.exports = {
    Validator,
    banner,
    notice,
    user,
    category,
    gallery,
    collection,
    wallpaper
};
